<?php

/**
 * LEAGUEMan
 * 
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
class LM_Table_Event extends LM_Table
{
    /** @var int Primary Key */
    public $event_id;
    /** @var int references LM_Table_Match */
    public $event_match;
    /** @var int references LM_Table_Playermap */
    public $event_playermap;
    /** @var int minute */
    public $event_minute;
    /** @var int references LM_Table_Eventtype */
    public $event_type;
    /** @var string text */
    public $event_text;
    /** @var string short text */
    public $event_text_short;


    public function __construct($db)
    {
        parent::__construct('#__leagueman_event', 'event_id', $db);
        $this->eventtypes = array();
    }

    public function getID()
    {
        return $this->event_id;
    }

    public function getPlayermap()
    {
        return $this->event_playermap;
    }

    public function getType()
    {
        return $this->event_type;
    }

    public function getEventtype($id)
    {

        $eventmap = LM_Table_Eventmap::getInstance($this->_db);
        return $eventmap->getEventtype($id);
    }

    public function filterbyMatch($match_id)
    {
        $this->addFilter("event_match = " . intval($match_id));
    }

    public function getRows($field = "", $limitstart = 0, $limit = 10)
    {

        $limitstart = intval($limitstart);
        $limit = intval($limit);

        $limitation = ($limit > 0) ? "LIMIT $limitstart, $limit" : "";

        $sql = "SELECT * FROM #__leagueman_event "
                . $this->getFilter() . "
			  ORDER BY event_minute $limitation";
        $this->_db->setQuery($sql);

        return $this->_db->loadObjectList($field);
    }

    public function getTotalRows()
    {
        $sql = "SELECT COUNT(event_id) FROM #__leagueman_event " . $this->getFilter();
        $this->_db->setQuery($sql);
        return $this->_db->loadResult();
    }

}